package Colecciones;

import Modelo.EstructuraFila;
import Modelo.PsCrseCatalog;
import Modelo.PsCrseComponent;
import Modelo.PsCrseOffer;
import Modelo.TransaccionSql;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;

public class InsertarCurso
{
  public static void insertar(PsCrseCatalog obj)
    throws MetadataException, IllegalAccessException, InvocationTargetException, SQLException
  {
    EstructuraFila ef = PsCrseCatalog.getEstructuraFila();
    String tableName = PsCrseCatalog.getTableName();
    String strInsert = Utils.getInsertString(obj, ef, tableName);

    TransaccionSql.insertar(strInsert);
  }

  public static void insertar(PsCrseComponent obj)
    throws MetadataException, IllegalAccessException, InvocationTargetException, SQLException
  {
    EstructuraFila ef = PsCrseComponent.getEstructuraFila();
    String tableName = PsCrseComponent.getTableName();
    String strInsert = Utils.getInsertString(obj, ef, tableName);

    TransaccionSql.insertar(strInsert);
  }

  public static void insertar(PsCrseOffer obj)
    throws MetadataException, IllegalAccessException, InvocationTargetException, SQLException
  {
    EstructuraFila ef = PsCrseOffer.getEstructuraFila();
    String tableName = PsCrseOffer.getTableName();
    String strInsert = Utils.getInsertString(obj, ef, tableName);

    TransaccionSql.insertar(strInsert);
  }

  public static synchronized void crearCurso(PsCrseCatalog courseCatalog, PsCrseComponent courseComponent, PsCrseOffer courseOffer)
  {
    try
    {
      String crseid = Curso.getNewCrseId();

      courseCatalog.setCrse_id(crseid);
      courseComponent.setCrse_id(crseid);
      courseOffer.setCrse_id(crseid);

      insertar(courseCatalog);
      insertar(courseComponent);
      insertar(courseOffer);
    }
    catch (SQLException ex)
    {
      ex.printStackTrace();
    }
    catch (IllegalAccessException ex)
    {
      ex.printStackTrace();
    }
    catch (InvocationTargetException ex)
    {
      ex.printStackTrace();
    }
    catch (MetadataException ex)
    {
      ex.printStackTrace();
    }
  }
}